<%-- 
    Document   : comprar
    Created on : 31-dic-2012, 13:49:49
    Author     : Cannibal-Slayer
--%>

<%@page import="com.sun.xml.internal.messaging.saaj.util.TeeInputStream"%>
<%@page contentType="text/html" pageEncoding="UTF-8" session="true" import="java.util.*" import="recursos.*" import="CapaLogica.*"%>

<%
 
    interfaz_com com = new interfaz_com();
    LinkedList<Categoria> lista = com.pedir_categorias();
%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>guatebay</title>
        <meta charset="utf-8">

        
        <script type="text/javascript" src="js/ajax-dynamic-content.js"></script>
        <script type="text/javascript" src="js/ajax.js"></script>
        <script type="text/javascript" src="js/ajax-tooltip.js">
        </script>	
        <link rel="stylesheet" href="css/ajax-tooltip.css" media="screen" type="text/css">
        <link rel="stylesheet" href="css/ajax-tooltip-demo.css" media="screen" type="text/css">
        <link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
        <link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
        <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
        <script type="text/javascript" src="js/jquery-1.5.2.js" ></script>
        <script type="text/javascript" src="js/cufon-yui.js"></script>
        <script type="text/javascript" src="js/cufon-replace.js"></script>
        <script type="text/javascript" src="js/Amaranth_400.font.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
        <script type="text/javascript" src="js/scroll.js"></script>
        <script type="text/javascript" src="js/atooltip.jquery.js"></script>
        <script>
            function eliminar(id_articulo)
            {   var xmlhttp;
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET","carrito_jsp.jsp?id_eliminado="+id_articulo,true);
                xmlhttp.send();
            }
        </script>
        <script>
            function loadXMLDoc(id_articulo)
            {
    
                var xmlhttp;
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET","carrito_jsp.jsp?id_articulo="+id_articulo,true);
                xmlhttp.send();
            }
        </script>
        <script>
            function Ejecutar(tipo)
            {
                var xmlhttp;
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById("dinamico").innerHTML=xmlhttp.responseText;
                    }
                }
                var selectBox = document.getElementById("catalogos");
                var selectedValue = selectBox.options[selectBox.selectedIndex].value;
                alert(selectedValue);
                xmlhttp.open("GET","cargar_catalogo.jsp?tipo=" + selectedValue,true);
                xmlhttp.send();
            }
        </script>

    </head>
    <body>       
        <div class="extra">
            <div id="page_3">
                <div class="main">
                    <!--header -->

                    <table width="800" border="1" id="encabezado" > 
                        <tr> 
                            <td width="600" align="center"><p align="left"> <a target="frame"><img src="images/guatebay_logo.jpg" alt="">      </a>  </p> </td> 
                            <td width="800" align="center">
                                <br>    
                                <p align="right"> 
                                    <%
                                        String usuario = (String) session.getAttribute("usuario");
                                        out.print("Bienvenido: " + usuario);
                                    %>
                                </p>
                                <p align="right"> <a href="">Cerrar Sesion</a></p>   
                            </td> 
                        </tr>
                    </table>

                    <header>  
                        <br>  
                        <nav>
                            <ul class="menu">
                                <li><a href="catalogo.jsp">Catálogo</a></li>
                                <li><a href="vender.jsp">Vender</a></li>
                                <li><a href="comprar.jsp">Comprar</a></li>
                                <li><a href="#page_2">Perfil</a></li>
                            </ul>
                        </nav>
                    </header>
                    <!--header end-->
                    <!--content -->                    
                    <section class="content">
                        <h2>Listado de Catalogos</h2>
                        <%
                        

                            out.print("<SELECT id=\"catalogos\" SIZE=1 onchange=\"Ejecutar();\">");
                            for (Categoria tipo : lista) {
                                out.print("<OPTION value=\"" + tipo.getIdCategoria() + "\"> " + tipo.getNombre() + "</OPTION>");
                            }
                            out.print("</SELECT>");

                        %>
                        <div id="dinamico"></div>
                    </section>
                    <!--content end-->
                 </div>

                <div class="block">

                    <div id="myDiv">
                        <%
                          LinkedList<articulo_carrito> carrito = (LinkedList<articulo_carrito>) session.getAttribute("carrito");

                        if (carrito.size()==0){%>
                        <h2> Carrito de Compras Vacio</h2></div>
                        <%}else{
                                %>
                              Carrito (<%out.println(carrito.size());%>)  
                              
                <ul class="icons">

                    <%
                        double total = 0;
                        for (articulo_carrito articulo : carrito) {

                            out.println("<li><button type=\"button\" onclick=\"eliminar(" + articulo.articuloCodigo + ")\"><img src=\"images/remove.gif\" alt=\"\"></button>"
                                    + "<a href=\"#\" onmouseover=\"ajax_showTooltip(window.event,'demo-pages/info_articulo.jsp?id=" + articulo.articuloCodigo + "',this);return false\" >" + articulo.articuloNombre + "</a> </li>");
                            total += articulo.articuloPrecio;
                        }
                        
                        
                        %>
                    
                    </ul>

                <br>
                <br>
                <strong>Total:</strong><%out.println("" + total);%>
                <br>
                </div>
                <a href="comprar.jsp"> Pagar Carrito</a>
                    <%}
                    %>  
                         

            
                </div>

                <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            </div>
        </div>
        <div class="main">  
            <!--footer -->
            <footer>
                <ul class="icons">
                    <li>Análisis y Diseño de Sistemas 2 (Proyecto de Clase)</li>
                    <li><a href="#" class="normaltip"><img src="images/icon1.jpg" alt=""></a></li>
                    <li><a href="#" class="normaltip"><img src="images/icon2.jpg" alt=""></a></li>
                    <li><a href="#" class="normaltip"><img src="images/icon3.jpg" alt=""></a></li>
                    <li><a href="#" class="normaltip"><img src="images/icon4.jpg" alt=""></a></li>
                    <li><a href="#" class="normaltip"><img src="images/icon5.jpg" alt=""></a></li>
                    <li><a href="#" class="normaltip"><img src="images/icon6.jpg" alt=""></a></li>
                </ul>
            </footer>
            <!--footer end-->
        </div>    
    </body>
</html>

